import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart';
import 'package:get/get.dart';
import 'package:untitled/Page/home/home_bar/app_bar_controller.dart';

class HomeBar extends GetView<HomeBarController>
    implements PreferredSizeWidget, TickerProvider {
  var tabs = <BadgeTab>[];
  @override
  Widget build(BuildContext context) {
    tabs.add(BadgeTab(text: "精选", badgeText: "新"));
    tabs.add(BadgeTab(text: "平台活动", badgeNum: 22));
    tabs.add(BadgeTab(text: "协助", badgeNum: 20));
    TabController tabController =
        // ignore: prefer_const_constructors
        TabController(length: tabs.length, vsync: this);
    return GetBuilder(
        init: HomeBarController(),
        initState: (_) {},
        builder: (HomeBarController ctl) {
          return Stack(
            children: [
              Padding(
                padding: const EdgeInsets.fromLTRB(50, 0, 50, 0),
                child: BrnTabBar(
                  controller: tabController,
                  backgroundcolor: const Color.fromARGB(0, 0, 0, 0),
                  tabs: tabs,
                  padding: const EdgeInsets.fromLTRB(0, 50, 0, 0),
                  mode: BrnTabBarBadgeMode.origin,
                  isScroll: false,
                  labelPadding:
                      const EdgeInsets.only(left: 20, right: 12, bottom: 10),
                  indicatorWeight: 6,
                  indicatorWidth: 60,
                  indicatorPadding: const EdgeInsets.only(left: 10),
                  onTap: (state, index) {
                    BrnToast.show("点击了$index", context);
                  },
                ),
              ),
              Positioned(
                top: 40,
                left: 10,
                child: IconButton(
                    onPressed: () {},
                    // ignore: prefer_const_constructors
                    icon: const Icon(Icons.add_circle_outline,
                        color: Colors.black38)),
              ),
              Positioned(
                top: 40,
                right: 10,
                child: IconButton(
                    onPressed: () {},
                    // ignore: prefer_const_constructors
                    icon: const Icon(Icons.search, color: Colors.black38)),
              )
            ],
          );
        });
  }

  @override
  Size get preferredSize => const Size.fromHeight(kToolbarHeight);

  @override
  Ticker createTicker(TickerCallback onTick) {
    return Ticker(onTick);
  }
}
